package cn.ava.pet.controller;

import cn.ava.pet.service.IPetOnlineAuditLogService;
import cn.ava.pet.domain.PetOnlineAuditLog;
import cn.ava.pet.query.PetOnlineAuditLogQuery;
import cn.ava.basic.utils.AjaxResult;
import cn.ava.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: PetOnlineAuditLogController
 * @Description: 宠物审核日志
 * @Author: Avavaava
 * @Date: 2022/7/26 16:42
 * @version: 23.53
 *
 */
@RestController
@RequestMapping("/petOnlineAuditLog")
public class PetOnlineAuditLogController {
    @Autowired
    public IPetOnlineAuditLogService petOnlineAuditLogService;


    /**
     * 保存和修改公用的
     * @param petOnlineAuditLog  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody PetOnlineAuditLog petOnlineAuditLog){
        try {
            if( petOnlineAuditLog.getId()!=null)
                petOnlineAuditLogService.update(petOnlineAuditLog);
            else
                petOnlineAuditLogService.add(petOnlineAuditLog);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace(); 
            return new AjaxResult().setMessage("服务器崩溃！").setSuccess(false);
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            petOnlineAuditLogService.delete(id);
            return new AjaxResult();
        } catch (Exception e) {
        e.printStackTrace();
            return new AjaxResult().setMessage("服务器崩溃！").setSuccess(false);
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
    public PetOnlineAuditLog getById(@PathVariable("id")Long id)
    {
        return petOnlineAuditLogService.getById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    public List<PetOnlineAuditLog> list(){

        return petOnlineAuditLogService.loadAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping()
    public PageList<PetOnlineAuditLog> json(@RequestBody PetOnlineAuditLogQuery query)
    {
        return petOnlineAuditLogService.queryData(query);
    }



    @PatchMapping
    public AjaxResult batchDelete(@RequestBody Long[] id) {
        try {
            petOnlineAuditLogService.batchDelete(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setMessage("服务器崩溃！").setSuccess(false);
        }
    }

}
